package ro.sergiu.finder.models.frame;

import java.awt.Component;
import java.awt.Dimension;
import ro.sergiu.finder.models.property.PropertyEditorGenerator;

/**
 *
 * @author toporjinschi
 */
public class FrameModelPropertyEditor extends PropertyEditorGenerator {

    private FrameModelPanel editor = null;

    public FrameModelPropertyEditor() {
        editor = new FrameModelPanel();
        setValue(getDefaultValue());
    }

    @Override
    public Component getCustomEditor() {
        return editor;
    }

    @Override
    public Object getValue() {
        FrameModel ret = new FrameModel();
        ret.setTitle(editor.title.getText());
        ret.setSize(new Dimension((Integer) editor.sizeWidth.getValue(), (Integer) editor.sizeHeight.getValue()));
        ret.setMaximumSize(new Dimension((Integer) editor.maxWidth.getValue(), (Integer) editor.maxHeight.getValue()));
        ret.setPreferredSize(new Dimension((Integer) editor.prefWidth.getValue(), (Integer) editor.prefHeight.getValue()));
        ret.setMinimumSize(new Dimension((Integer) editor.minWidth.getValue(), (Integer) editor.minHeight.getValue()));
        ret.setResizable(editor.resizable.isSelected());
        ret.setResizable(editor.resizable.isSelected());
        return ret;
    }

    @Override
    public final void setValue(Object bean) {
        if (bean == null) {
            bean = this.getDefaultValue();
        }
        FrameModel windowCustomizer = (FrameModel) bean;
        editor.title.setText(windowCustomizer.getTitle());
        editor.resizable.setSelected(windowCustomizer.isResizable());
        editor.sizeHeight.setValue(windowCustomizer.getSize().height);
        editor.sizeWidth.setValue(windowCustomizer.getSize().width);
        editor.maxHeight.setValue(windowCustomizer.getMaximumSize().height);
        editor.maxWidth.setValue(windowCustomizer.getMaximumSize().width);
        editor.minHeight.setValue(windowCustomizer.getMinimumSize().height);
        editor.minWidth.setValue(windowCustomizer.getMinimumSize().width);
        editor.prefHeight.setValue(windowCustomizer.getPreferredSize().height);
        editor.prefWidth.setValue(windowCustomizer.getPreferredSize().width);
        super.setValue(bean);
    }

    @Override
    public final Object getDefaultValue() {
        return new FrameModel();
    }
}
